¿Qué hacemos en este cuaderno?

Defino el periodo de estudio de la investigación. Desde el inicio se tenía claro que sería desde el inicio de la pandemia hasta el final de la segunda ola de fallecimientos, por lo que es necesario definir exactamente cuándo termina esta.

Para ello, se ha seguido la metodología de Pande et al. (2022, p. 6).

Iniciamos

Al igual que con los cuadernos de Python, es necesario setear un directorio de trabajo.

setwd("G:/Mi unidad/Documentos personales/1-Investigaciones y análisis/Perú una país de provincias/revisión 1")

Cargo las librerías.

library(plotly)
## Warning: package 'plotly' was built under R version 4.2.2
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.2.2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(ggplot2)
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.2.2
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(readr)

Empezamos cargando el archivo que viene de NOTI-SINADEF con la cantidad de fallecidos diarios en todo el país.

# Leer el archivo Parquet
fallecidos_covid <- read_delim("rawdata/fallecidos_covid.csv", 
                               ";", escape_double = FALSE, col_types = cols(FECHA_CORTE = col_date(format = "%Y%m%d"), 
                                                                            FECHA_FALLECIMIENTO = col_date(format = "%Y%m%d")), 
                               trim_ws = TRUE)
head(fallecidos_covid)
## # A tibble: 6 × 10
##   FECHA_CORTE FECHA_FALLE…¹ EDAD_…² SEXO  CLASI…³ DEPAR…⁴ PROVI…⁵ DISTR…⁶ UBIGEO
##   <date>      <date>          <dbl> <chr> <chr>   <chr>   <chr>   <chr>   <chr> 
## 1 2023-01-20  2021-05-12         88 FEME… Criter… AREQUI… AREQUI… PAUCAR… 040112
## 2 2023-01-20  2021-06-24         58 MASC… Criter… AREQUI… AREQUI… PAUCAR… 040112
## 3 2023-01-20  2021-04-26         84 MASC… Criter… LA LIB… SANCHE… CHUGAY  130902
## 4 2023-01-20  2021-03-15         64 MASC… Criter… LA LIB… SANTIA… CACHIC… 131003
## 5 2023-01-20  2021-05-04         62 MASC… Criter… LIMA    HUARAL  CHANCAY 150605
## 6 2023-01-20  2021-03-21         61 FEME… Criter… LIMA    HUARAL  HUARAL  150601
## # … with 1 more variable: UUID <dbl>, and abbreviated variable names
## #   ¹​FECHA_FALLECIMIENTO, ²​EDAD_DECLARADA, ³​CLASIFICACION_DEF, ⁴​DEPARTAMENTO,
## #   ⁵​PROVINCIA, ⁶​DISTRITO

Creo una columna que asuma que cada fila se cuente como un fallecimiento.

fallecidos_covid$Muertes <- rep(1)

Filtramos datos para excluir a Lima y Callao.

fallecidos_covid <- fallecidos_covid %>%
                    filter(PROVINCIA != "LIMA")%>%
                    filter(PROVINCIA != "CALLAO")

Obtenemos fallecimientos por fechas.

olas<- fallecidos_covid %>%
  group_by(FECHA_FALLECIMIENTO) %>%
  summarise(Muertes=sum(Muertes))

Graficamos.

grafico <- ggplot(olas) +
  aes(x = FECHA_FALLECIMIENTO, y = Muertes) +
  geom_line(size = 0.5, colour = "#112446") +
  theme_minimal()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
ggplotly(grafico)

Ahora que ya tenemos el gráfico, procedemos a reproducir la metodología de Pandey et al. (2022). Para ello será necesario identificar el valor de h, H1 y h1 de la segunda ola.

olasf <- olas[olas$FECHA_FALLECIMIENTO >= as.Date("2021-08-01") & 
               olas$FECHA_FALLECIMIENTO <= as.Date("2022-01-15"),]

olasf2 <- olas[olas$FECHA_FALLECIMIENTO >= as.Date("2021-03-27") & 
                olas$FECHA_FALLECIMIENTO <= as.Date("2021-06-01"),]

Obtenemos la fecha con menor cantidad de contagios.

h <- olasf$FECHA_FALLECIMIENTO[which.min(olasf$Muertes)] #10
H1 <- olasf2$FECHA_FALLECIMIENTO[which.max(olasf2$Muertes)] #494

h1 <- 0.05*(494-10)+10 #Tiene que ser mayor o igual al resultado
#El final de la segunda ola de fallecimientos fuera de Lima
#y Callao seria el 2021-08-16 con 34 fallecidos.

Por tanto, las fechas de corte son el 2020-03-03 (inicio de fallecimientos) y el 2021-08-16 (final de segunda ola).